package com.smart.wap.bodys;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.crypto.digest.DigestUtil;
import com.smart.common.entities.domain.SmartPattern;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;

/**
 * @author Administrator
 */
public class LoginBody {

    @Data
    @ApiModel("AppLoginBody1")
    public static class LoadCaptchaBody implements Serializable {
        @ApiModelProperty(value = "手机号码", required = true)
        @NotBlank(message = "手机号码 不能为空")
        @Pattern(regexp = SmartPattern.PHONE, message = "手机号码 格式不正确")
        private String phoneNumber;


        @ApiModelProperty(value = "11位时间戳", required = true)
        @NotNull(message = "时间戳 不能为空")
        private Long timestamp;


        @ApiModelProperty(value = "签名字符串  算法:大写32位MD5(SMART-手机号码-时间戳) ,中间有短横线 ", required = true)
        @Length(min = 32, max = 32, message = "获取短信签名错误")
        private String sign;


        public void checkSign() {
            String sourceStr = String.format("SMART-%s-%s", this.phoneNumber, this.timestamp);
            String sign2 = DigestUtil.md5Hex(sourceStr).toUpperCase();
            Assert.equals(this.sign, sign2, "获取短信验证码签名错误");
            long abs = Math.abs(DateUtil.currentSeconds() - this.timestamp);
            Assert.isTrue(abs <= 300L, "设备时间异常:请校验当前设备的时间后再进行短信发送");
        }
    }


    /**
     * 电话号码登录对象
     *
     * @author xiaxuqiu
     * @date 2023/09/10
     */

    @Data
    @ApiModel("AppLoginBody2")
    public static class SmsLoginBody implements Serializable {


        @ApiModelProperty(value = "手机号码", required = true)
        @NotBlank(message = "手机号码 不能为空")
        @Pattern(regexp = SmartPattern.PHONE, message = "手机号码 格式不正确")
        private String phoneNumber;

        @ApiModelProperty(value = "手机验证码", notes = "测试验证码:6个0", required = true)
        @NotBlank(message = "手机验证码 不能为空")
        @Length(min = 4, max = 6, message = "手机验证码 字符长度错误")
        private String captcha;


        @ApiModelProperty(value = "openId类型", required = true)
        @NotNull(message = "openId 类型不能为空")
        private OpenIdKind openIdKind;


        @ApiModelProperty("OpenId 字符串")
        @Length(max = 50, message = "openId格式错误")
        private String openId;

        @ApiModelProperty("邀请模式 接收两个值 B2C / C2C")
        private String inviteMode;

        @ApiModelProperty(value = "注册邀请码" )
        private Long inviteCode ;

    }


    @Data
    @ApiModel("AppLoginBody4")
    public static class RefreshTokenBody implements Serializable {

        @ApiModelProperty(value = "refreshToken 字符串", required = true)
        @Length(max = 32, message = "refreshToken 格式错误")
        @Pattern(regexp = SmartPattern.MD5, message = "refreshToken 令牌格式不正确")
        private String refreshToken;

    }


    @Data
    @ApiModel("AppLoginBody5")
    public static class OneKeyLoginBody implements Serializable {

        @ApiModelProperty(value = "号码认证服务AccessToken", required = true)
        @NotBlank(message = "号码认证服务AccessToken 不能为空")
        private String accessToken;

        @ApiModelProperty("邀请模式 接收两个值 B2C / C2C")
        private String inviteMode;

        @ApiModelProperty(value = "注册邀请码" )
        private Long inviteCode ;

    }


    @Data
    @ApiModel("AppLoginBody6")
    public static class WxLoginBody implements Serializable {

        @ApiModelProperty(value = "微信登录Code", required = true)
        @NotBlank(message = "微信登录Code 不能为空")
        private String code;


        @ApiModelProperty("邀请模式 接收两个值 B2C / C2C")
        private String inviteMode;

        @ApiModelProperty(value = "注册邀请码" )
        private Long inviteCode ;

    }

}
